package com.jh.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jh.annotation.AutoFill;
import com.jh.vo.InventoryDistributionVO;
import com.jh.dto.ProductPageQueryRightDTO;
import com.jh.dto.StoreCashierProductPageQueryDTO;
import com.jh.entity.PIdAndColor;
import com.jh.entity.Product;
import com.jh.enumeration.OperationType;
import com.jh.vo.ProductPageVO;
import com.jh.vo.StoreCashierProductVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProductMapper extends BaseMapper<Product> {
    /**
     * 根据id删除商品
     *
     * @param id
     */
    @Delete("delete from jh_clothing.product where id=#{id}")
    void deleteByid(Long id) ;

    /**
     * 商品分页查询
     *
     * @param productPageQueryRightDTO
     * @return
     */
    Page<ProductPageVO> pageQuery(Page<ProductPageVO> page, @Param("productPageQueryRightDTO") ProductPageQueryRightDTO productPageQueryRightDTO);

    /**
     * 根据id查询产品信息
     *
     * @param id
     * @return
     */
    @Select("select * from jh_clothing.product where id = #{id}")
    Product getByid(Long id);

    /**
     * 修改产品信息
     *
     * @param product
     */
    @AutoFill(value= OperationType.UPDATE)
    @Update("update jh_clothing.product set brand=#{brand},productCode=#{productCode},retailPrice=#{retailPrice},color=#{color} where id=#{id}")
    void update(Product product);

    /**
     * 分页查询收银台库存信息
     *
     * @param storeCashierProductPageQueryDTO
     * @return
     */
    Page<StoreCashierProductVO> page(Page<StoreCashierProductVO> page,@Param("storeCashierProductPageQueryDTO") StoreCashierProductPageQueryDTO storeCashierProductPageQueryDTO);

    /**
     * 工作台根据pId查询颜色和对应的id
     *
     * @param productCode
     * @return
     */
    @Select("select id,color from jh_clothing.product where productCode =#{productCode} and inventory>0")
    List<PIdAndColor> getPIdAndColorData(String productCode);

    List<InventoryDistributionVO> getInventoryDistribution();
}
